package com.wz.project.outStock.stockoutdetail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.outStock.stockoutdetail.domain.OutStockoutDetail;
import com.wz.project.outStock.stockoutdetail.service.IOutStockoutDetailService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 出库单据子表Controller
 * 
 * @author wz
 * @date 2022-09-08
 */
@Controller
@RequestMapping("/stockoutdetail/stockoutdetail")
public class OutStockoutDetailController extends BaseController
{
    private String prefix = "stockoutdetail/stockoutdetail";

    @Autowired
    private IOutStockoutDetailService outStockoutDetailService;

    @RequiresPermissions("stockoutdetail:stockoutdetail:view")
    @GetMapping()
    public String stockoutdetail()
    {
        return prefix + "/stockoutdetail";
    }

    /**
     * 查询出库单据子表列表
     */
//    @RequiresPermissions("stockoutdetail:stockoutdetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OutStockoutDetail outStockoutDetail)
    {
        startPage();
        List<OutStockoutDetail> list = outStockoutDetailService.selectOutStockoutDetailList(outStockoutDetail);
        return getDataTable(list);
    }

    /**
     * 导出出库单据子表列表
     */
    @RequiresPermissions("stockoutdetail:stockoutdetail:export")
    @Log(title = "出库单据子表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OutStockoutDetail outStockoutDetail)
    {
        List<OutStockoutDetail> list = outStockoutDetailService.selectOutStockoutDetailList(outStockoutDetail);
        ExcelUtil<OutStockoutDetail> util = new ExcelUtil<OutStockoutDetail>(OutStockoutDetail.class);
        return util.exportExcel(list, "stockoutdetail");
    }

    /**
     * 新增出库单据子表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库单据子表
     */
    @RequiresPermissions("stockoutdetail:stockoutdetail:add")
    @Log(title = "出库单据子表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OutStockoutDetail outStockoutDetail)
    {
        return toAjax(outStockoutDetailService.insertOutStockoutDetail(outStockoutDetail));
    }

    /**
     * 修改出库单据子表
     */
    @GetMapping("/edit/{stockoutDetailId}")
    public String edit(@PathVariable("stockoutDetailId") String stockoutDetailId, ModelMap mmap)
    {
        OutStockoutDetail outStockoutDetail = outStockoutDetailService.selectOutStockoutDetailById(stockoutDetailId);
        mmap.put("outStockoutDetail", outStockoutDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库单据子表
     */
    @RequiresPermissions("stockoutdetail:stockoutdetail:edit")
    @Log(title = "出库单据子表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OutStockoutDetail outStockoutDetail)
    {
        return toAjax(outStockoutDetailService.updateOutStockoutDetail(outStockoutDetail));
    }

    /**
     * 删除出库单据子表
     */
    @RequiresPermissions("stockoutdetail:stockoutdetail:remove")
    @Log(title = "出库单据子表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(outStockoutDetailService.deleteOutStockoutDetailByIds(ids));
    }
}
